﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmallBonesDB;

namespace db
{
	public partial class Form1 : Form
	{
		static	public string debugText;

		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			IceBird.AssignResult res = (link.DBSignIn(text1.Text,text2.Text));
			infomation.Text = res.userId + " " + res.assignState.ToString();
		}

		private void buttonGetGroup_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			//link.GetGroups(1, 5);
			IceBird.GroupSet lis = link.GetGroups(Convert.ToInt32(text1.Text), Convert.ToInt32(text2.Text), IceBird.SortForm.LAST);
			infomation.Text ="";
			if (lis.err != IceBird.DBError.OK){
				infomation.Text += lis.err.ToString() + "\n";
				return;
			}
			infomation.Text += lis.groupCount + "\n";
			for(int i = 0 ; i < lis.Groups.Count ;i++)
				infomation.Text += ((SmallBonesDB.Group)lis.Groups[i]).ToString() + "\n";
		}

		private void buttonDebug_Click(object sender, EventArgs e)
		{
			infomation.Text = debugText;
		}

		private void buttonReply_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			//link.GetGroups(1, 5);
			IceBird.TopicSet lis = link.GetTopics(1, 101, Convert.ToInt32(text1.Text));
			infomation.Text = "";
			if (lis.err != IceBird.DBError.OK){
				infomation.Text += lis.err.ToString() + "\n";
				return;
			}
			infomation.Text += ((SmallBonesDB.Group)lis.group).ToString() + "\n";
			for (int i = 0; i < lis.Topics.Count; i++)
				infomation.Text += ((SmallBonesDB.Topic)lis.Topics[i]).ToString() + "\n";
		}

		private void buttonTime_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			infomation.Text = link.CommitReply(1, text1.Text, Convert.ToInt32(text2.Text)).ToString();
		}

		private void buttonGetReply_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			IceBird.MessageSet lis = link.GetReplies(1, 101, Convert.ToInt32(text1.Text));
			infomation.Text = "";
			if (lis.err != IceBird.DBError.OK){
				infomation.Text += lis.err.ToString() + "\n";
				return;
			}
			infomation.Text += ((SmallBonesDB.Topic)lis.topic).ToString() + "\n";
			for (int i = 0; i < lis.Messages.Count; i++)
				infomation.Text += ((SmallBonesDB.Message)lis.Messages[i]).ToString() + "\n";
		}

		private void buttonNewTopic_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			IceBird.CreateResult res = link.NewTopic(123, text1.Text, Convert.ToInt32(text2.Text));
			infomation.Text = res.createState.ToString() + "\n" + res.id.ToString() + "\n";
		}

		private void buttonNewGroup_Click(object sender, EventArgs e)
		{
			DBToNetwork link = new DBToNetwork();
			IceBird.CreateResult res = link.NewGroup(text1.Text);
			infomation.Text = res.createState.ToString() + "\n" + res.id.ToString() + "\n";
		}
	}
}
